package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsOrderGoodsMapper;
import com.qf.mapper.DtsOrderMapper;
import com.qf.mapper.DtsOrdersGoodsMapper;
import com.qf.mapper.DtsUserMapper;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsOrderGoods;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsGoodsOrderService;
import com.qf.util.ResponseUtil;
import com.qf.vo.GoodsCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class DtsGoodsOrderServiceImpl implements DtsGoodsOrderService {
    @Autowired
    private DtsOrdersGoodsMapper ordersGoodsMapper;
    @Autowired
    private DtsOrderMapper orderMapper;
    @Autowired
    private DtsUserMapper userMapper;
    @Autowired
    DtsOrderGoodsMapper orderGoodsMapper;

    @Override
    public int findCountByGid(Integer id) {
        LambdaQueryWrapper<DtsOrderGoods> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsOrderGoods::getDeleted, false);
        wrapper.eq(DtsOrderGoods::getGoodsId, id);
        return orderGoodsMapper.selectCount(wrapper);
    }

    @Override
    public List<GoodsCountVo> queryGoodsCountVo(int rang) {
        return orderGoodsMapper.queryUserStatis(rang);
    }

    @Override
    public Object findById(Integer id) {
        DtsOrder order = orderMapper.selectById(id);

        DtsUser user = userMapper.selectById(order.getUserId());
        HashMap<String, Object> users = new HashMap<>();
        users.put("nickname",user.getNickname());
        users.put("avatar",user.getAvatar());
        List<DtsOrderGoods> orderGoods = ordersGoodsMapper.findByOrderId(id);
        HashMap<String, Object> data = new HashMap<>();
        data.put("orderGoods",orderGoods);
        data.put("user",users);
        data.put("order",order);
        return ResponseUtil.ok(data);

    }




}
